package homework.homework_8.ktv;

import java.util.ArrayList;

/**
 * @author 朱
 * @date 2019040821:21
 */
public class KTVDaoImp implements KTVDao {
    ArrayList<KTV> arrayList=new ArrayList<KTV>();
    Object object=arrayList;
    @Override
    public void add(KTV ktv) {
        arrayList.add(ktv);
        System.out.println("当前歌曲列表："+object);
    }

    @Override
    public void forward(String name) {
        KTV ktv=new KTV(name);
        for (int i = 0; i <arrayList.size() ; i++) {
            if (arrayList.get(i).getName().equals(name)){
                arrayList.remove(ktv);
                arrayList.add(arrayList.size()-1,ktv);
                System.out.println("当前歌曲列表："+object);
            }else {
                System.out.println("歌曲不存在");
            }
        }
    }

    @Override
    public void top(String name) {
        KTV ktv=new KTV(name);
        if (arrayList.contains(ktv)){
            arrayList.remove(ktv);
            arrayList.add(0,ktv);
            System.out.println("当前歌曲列表："+object);
        }else {
            System.out.println("歌曲不存在");
        }
    }
}
